package LC;

/**
 * @ClassName LC36
 * @Description: TODO
 * @Author hl
 * @Date 2021/4/18
 * @Version V1.0
 **/
public class LC36 {
    public boolean isValidSudoku(char[][] board) {
        int[][] rows = new int[9][9];
        int[][] col = new int[9][9];
        int[][] sbox = new int[9][9];
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
                char target = board[i][j];
                if (target != '.') {
                    int num = target - '1';
                    if (rows[i][num] == 1) return false;
                    else rows[i][num] = 1;

                    if (col[j][num] == 1) return false;
                    else col[j][num] = 1;

                    if (sbox[i / 3 * 3 + j / 3][num] == 1) return false;
                    else sbox[i / 3 * 3 + j / 3][num] = 1;
                }
            }
        }
        return true;
    }
}
